namespace Digitalmes.Application.Mes;

/// <summary>
/// 产品返工单
/// </summary>
public sealed class ReworkDocDto : Dto
{
    /// <summary>
    /// 产品返工单据号
    /// </summary>
    [Required, NotNull]
    [StringLength(32)]
    public string? Doc { get; set; }

    /// <summary>
    /// SN
    /// </summary>
    [Required, NotNull]
    [StringLength(64)]
    public string? Sn { get; set; }

    /// <summary>
    /// NG 的产线Id
    /// </summary>
    public long NgLineId { get; set; }

    /// <summary>
    /// NG 的产线编号
    /// </summary>
    public string? NgLineCode { get; set; }

    /// <summary>
    /// NG 的工位Id
    /// </summary>
    public long NgOpId { get; set; }

    /// <summary>
    /// NG 的工位编号
    /// </summary>
    public string? NgOpCode { get; set; }

    /// <summary>
    /// NG 的工序Id
    /// </summary>
    public long NgProcId { get; set; }

    /// <summary>
    /// NG 的工序编号
    /// </summary>
    public string? NgProcCode { get; set; }

    /// <summary>
    /// 当前所在的工艺路线 Id。没有则为 0。
    /// </summary>
    /// <remarks>线外站时设置为 0。</remarks>
    public long NgRoutingId { get; set; }

    /// <summary>
    /// 当前所在的工艺路线编号。
    /// </summary>
    /// <remarks>线外站产品，可设置为空。</remarks>
    [NotNull]
    public string? NgRoutingCode { get; set; }

    /// <summary>
    /// NG 步序编号集合。
    /// </summary>
    /// <remarks></remarks>
    public List<int>? NgSteps { get; set; }

    /// <summary>
    /// 返工类型（离线返工/在线返工）
    /// </summary>
    public ReworkTypeEnum ReworkType { get; set; }

    public string? ReworkTypeDesc => ReworkType.Description();

    /// <summary>
    /// 针对离线返工，返工后是否需要再重新上线。
    /// </summary>
    public bool NeedRelaunch { get; set; } = true;

    /// <summary>
    /// 返工后重新上线的工序 Id。
    /// </summary>
    /// <remarks>一般装配站返工重新上线，默认到NG的后一工序；检测站返工再上新，到NG工序</remarks>
    public long RelaunchProcId { get; set; }

    /// <summary>
    /// 返工后重新上线的工序编号。
    /// </summary>
    public string? RelaunchProcCode { get; set; }

    /// <summary>
    /// 返工后重新上线开始作业的步序编号。
    /// </summary>
    /// <remarks></remarks>
    public int RelaunchProcStep { get; set; }

    /// <summary>
    /// 返工模板Id
    /// </summary>
    public long? TemplateId { get; set; }

    /// <summary>
    /// 返工模板名称
    /// </summary>
    public string? TemplateName { get; set; }

    /// 返工状态
    /// </summary>
    public ReworkStatusEnum Status { get; set; }

    public string? StatusDesc => Status.Description();

    /// <summary>
    /// 返工人员
    /// </summary>
    public string? Operator { get; set; }

    /// <summary>
    /// 返工完成时间
    /// </summary>
    public DateTime? CompletedTime { get; set; }

    /// <summary>
    /// 返修结果（1->OK;2->NG;3->报废）
    /// </summary>
    public ReworkResultEnum Result { get; set; }

    public string? ResultDesc => Result.Description();

    /// <summary>
    /// 针对离线返工，返工的产线编号
    /// </summary>
    public string? ReworkLineCode { get; set; }

    /// <summary>
    /// 针对离线返工，返工的工位编号
    /// </summary>
    public string? ReworkOpCode { get; set; }

    /// <summary>
    /// 备注
    /// </summary>
    public string? Remark { get; set; }

    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTime CreateTime { get; set; }

    /// <summary>
    /// 创建人
    /// </summary>
    public string? CreateUser { get; set; }

    /// <summary>
    /// 修改时间
    /// </summary>
    public DateTime? UpdateTime { get; set; }

    /// <summary>
    /// 修改人
    /// </summary>
    public string? UpdateUser { get; set; }

    /// <summary>
    /// 返工明细项
    /// </summary>
    public List<ReworkDocLineDto>? TemplateItems { get; set; }
}
